package com.impltest.demo8;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
/**
 * @author ext.yanghua1
 * 2023/6/27 18:58
 */
public class Testyh {
    public static void main(String[] args) {
//        String json="abc";
//        json="{\"chartType\":\""+json+"\"}";
//        System.out.println(json);

        comTxt();
    }
    /**
     * 对比两个文件内容
     */
    private  static void comTxt(){
        // 指定要读取的文本文件的路径
        String filePath2 = "D:\\ext.yanghua1\\Desktop\\aa.txt";
        String filePath = "D:\\ext.yanghua1\\Desktop\\bb.txt";
        Map<String, String> map = new HashMap<>();
        try {
            // 创建 File 对象
            File file = new File(filePath);
            // 创建 Scanner 对象，用于读取文件
            Scanner scanner = new Scanner(file);

            // 逐行读取文件内容
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                map.put(line,"1");
            }
            // 关闭 Scanner
            scanner.close();
        } catch (FileNotFoundException e) {
            System.out.println("文件未找到: " + filePath);
        }
        try {
            // 创建 File 对象
            File file2 = new File(filePath2);
            // 创建 Scanner 对象，用于读取文件
            Scanner scanner2 = new Scanner(file2);
            // 逐行读取文件内容
            while (scanner2.hasNextLine()) {
                String line2 = scanner2.nextLine();

                if (!map.containsKey(line2)){
                    System.out.println(line2);
                }

            }
            // 关闭 Scanner
            scanner2.close();
        } catch (FileNotFoundException e) {
            System.out.println("文件未找到: " + filePath);
        }

    }


}
